<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">
  <head>
  	<base href="<%=basePath%>">
  	<!-- jsp文件头和头部 -->
  	<%-- <%@ include file="../../system/admin/top.jsp"%>  --%>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>患者信息</title>
    <link rel="stylesheet" href="static/css/common.css">
    <link rel="stylesheet" href="static/css/bootstrap.css">
    <link rel="stylesheet" href="static/css/font-awesome-4.7.css">
    <link rel="stylesheet" href="static/css/hzxx.css">
    <script src="static/js/jquery-1.11.3.js"></script>
    <script src="static/js/bootstrap.js"></script>
    <!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<script type="text/javascript">
		$(top.hangge());
		var h = $(window).height();
		$('.main').css('height',h-40);
		$('input[type=radio]:checked').css('color','#007cde');
	</script>
   <!--  <script src="static/xw/js/patient_addPatient.js"></script>  -->
</head>
  <body>
    <div class="container-fluid" style="padding-left:0;padding-right:40px;" id="zhongxin">
        <div class="row">
            <!-- 患者主要信息展示页面 -->
            <div class="col-sm-12 col-md-12 col-lg-12 main">
                <form  id="patientForm" method="post" action="patient/saveP.do">
                    <!-- 患者来源 -->
                    <div class="r1">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>患者来源:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                        	<c:if test="${not empty pd.hzly }">
                        		${ pd.hzly }
                        		<input type="hidden" id="hzly" value="${pd.hzly }" name="hzly">
                        	</c:if>
                        	<c:if test="${empty pd.hzly }">
	                            <select id="hzly" name="hzly">
	                                <option value="" class="active">===请选择===</option>
	                                <option value="熟人介绍">熟人介绍</option>
	                                <option value="通过QQ联系介绍">通过QQ联系介绍</option>
	                            </select>
                        	</c:if>
                        </div>
                    </div> 
                    <!-- 患者姓名、性别 -->
                    <div class="r2">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>姓名:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <!-- 姓名输入框 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 box">
                                <input type="text" class="name" placeholder="请输入患者姓名" id="name" name="name" value="${ pd.name }">
                            </div>
                            <!-- 性别选择 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 sex">
                                <div class="left lf">
                                    <i>*</i>
                                    <span>姓别:</span>
                                </div>
                                <div class="right">
                                    <input type="radio" name="sex" id="male" value="男"  <c:if test="${pd.sex=='男'}"> checked="checked" </c:if> />
                                    <label for="male">男</label>
                                    <input type="radio" name="sex" id="female" value="女" <c:if test="${pd.sex=='女'}"> checked="checked" </c:if> />
                                    <label for="female">女</label>
                                </div>
                            </div>
                        </div>
                    </div> 
                    <!-- 年龄及联系方式 -->
                    <div class="r3">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>年龄:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <!-- 年龄输入框 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 box">
                                <input type="text" class="age" placeholder="请输入患者年龄" id="age" name="age" value="${ pd.age }"> &nbsp;&nbsp;岁
                            </div>
                            <!-- 联系方式 -->
                            <div class="col-sm-6 col-md-6 col-lg-6">
                                <div class="left lf">
                                    <i>*</i>
                                    <span>电话:</span>
                                </div>
                                <div class="right">
                                    <input type="text" class="phone" placeholder="请输入您的联系方式" id="phone" name="phone" value="${pd.phone }">
                                </div>
                            </div>
                        </div>
                    </div> 
                    <!-- 患者职业选择 -->
                    <div class="r4">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>职业:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="worker" placeholder="请输入患者职业" id="job" name="job" value="${pd.job }">
                        </div>
                    </div> 
                    <!-- 收货人 -->
                    <div class="r5">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>收货人:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="consignee" placeholder="请输入收货人姓名" id="shr" name="shr" value="${pd.shr }">
                        </div>
                    </div>   
                    <!-- 收货人 -->
                    <div class="r6">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>收货人地址:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="consignee" placeholder="请输入收货人地址" id="shrAddress" name="shrAddress" value="${pd.shraddress }">
                        </div>
                    </div>
                    <!-- 收货人联系电话 -->
                    <div class="r6">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>收货人联系电话:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="consignee" placeholder="请输入收货人联系电话" id="shrPhone" name="shrPhone" value="${pd.shrphone }">
                        </div>
                    </div>
                    <div class="r7">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>备注信息:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <textarea name="remark" id="remark" cols="30" rows="6" placeholder="请输入备注信息" class="textarea">${pd.remark }</textarea>
                        </div>
                        <div class="bottom col-sm-offset-5 col-sm-2 col-md-offset-5 col-md-2 col-lg-offset-5 col-lg-2">
	                        <a class="btn btn-success" style="width:100%;" id="submit">提交</a>
	                        <input type="hidden" id="hzId" value="${pd.id }" name="hzId">
	                    </div>
                    </div>                    
                </form>
            </div>
        </div>
    </div>
    <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
</body>
<script type="text/javascript">
		$(function() {
		    //点击提交
		    $("#submit").click(function(){
		   	 
			   	 //验证患者来源
			   	 if($("#hzly").val() == ""){
			   		 $("#hzly").tips({
			   			 side:3,
			   			 msg:'请选择患者来源',
			   			 bg:'#AE81FF',
			 	             time:2
			   		 });
			   		 $("#hzly").focus();
			   		 return false;
			   	 }
		   	
			   	 //验证姓名
			   	 if($("#name").val().trim() == ""){
			   		 $("#name").tips({
							side:3,
				            msg:'请输入患者姓名',
				            bg:'#AE81FF',
				            time:2
				        });
			   		 $("#name").focus();
			   		 return false ;
			   	 }
		   	
		   	 	//验证性别
			   	 if($('input[name="sex"]:checked').val() == null){
			   		 $(".sex").tips({
							side:3,
				            msg:'请选择性别',
				            bg:'#AE81FF',
				            time:3
				        });
			   		 $("#male").focus();
						return false;
			   	 }
		   	 
			   	 //验证年龄
			   	 var reg_age = /^([1-9])\d*$/;
			   	 if($("#age").val().trim() == ""){
			   		 $("#age").tips({
			 				side:3,
			 	            msg:'请输入年龄',
			 	            bg:'#AE81FF',
			 	            time:3
			 	        });
			    		 $("#age").focus();
			 			return false;
			   	 }else if( !reg_age.test($("#age").val().trim())){
			   		 $("#age").tips({
			  				side:3,
			  	            msg:'大于0非0开头的整数',
			  	            bg:'#AE81FF',
			  	            time:3
			  	        });
			     		 $("#age").focus();
			  			return false;
			   	 }
		   	 
			   	 //验证电话
			   	 var reg_phone = /^((1[3,8][0-9])|(15[0-35-9])|(14[5,7,9])|(17[0,1,3,5,6,7,8]))\d{8}$/;
			   	 if( $("#phone").val().trim() == ""){
			   		 $("#phone").tips({
			  				side:3,
			  	            msg:'请输入手机号',
			  	            bg:'#AE81FF',
			  	            time:3
			  	        });
			     		 $("#phone").focus();
			  			return false;
			   	 }else if($("#phone").val().trim().length != 11 && !reg_phone.test($("#phone").val().trim())){
			   		 $("#phone").tips({
			   				side:3,
			   	            msg:'手机号格式不正确',
			   	            bg:'#AE81FF',
			   	            time:3
			   	        });
			      		 $("#phone").focus();
			   			return false;
			   	 }
		   	 
			   	 //验证收货人电话
			   	 if($("#shrPhone").val().trim() !="" && !reg_phone.test($("#shrPhone").val().trim()) ){
			   		 $("#shrPhone").tips({
							side:3,
				            msg:'手机号格式不正确',
				            bg:'#AE81FF',
				            time:3
				        });
			   		 $("#shrPhone").focus();
						return false;
			   	 }
			   	 
			   	 if($("#hzId").val()!=""){
			   	 	$("#patientForm").submit();
				   	$("#zhongxin").hide();
					$("#zhongxin2").show();
			   	 }else{
				   	 var name = $("#name").val();
				   	 var phone = $("#phone").val();
				   	 $.ajax({
						type: "POST",
						url: '<%=basePath%>patient/hasP.do',
				    	data: {
				    		'name':name,
				    		'phone':phone
				    	},
						dataType:'json',
						cache: false,
						success: function(data){
							 if("success" == data.result){
								 alert("用户已存在");
								 document.getElementById("name").value="";
								 document.getElementById("phone").value="";
							 }else{
							   	 $("#patientForm").submit();
							   	 $("#zhongxin").hide();
								 $("#zhongxin2").show();
							 }
						}
					});
			   	 }
			   	 
			   	 
		   	 
		   	 /* $.ajax({
					type: "POST",
					url: 'patient/saveP.do',
			    	data: {
			    			hzId:$("#hzId").val(),
			    			hzly:$("#hzly").val(),
			    			name:$("#name").val().trim(),
			    			sex:$('input[name="sex"]:checked').val(),
			    			age:$("#age").val().trim(),
			    			phone:$("#phone").val().trim(),
			    			job:$("#job").val().trim(),
			    			shr:$("#shr").val().trim(),
			    			shrAddress:$("#shrAddress").val().trim(),
			    			shrPhone:$("#shrPhone").val().trim(),
			    			remark:$("#remark").val().trim()
			    			},
					dataType:'json',
					cache: false,
					success: function(data){
						 if("success" == data.msg){
							setTimeout(alert("提交成功！"),500);
							 window.location.reload(true);
						 }else{
							setTimeout(alert(data.msg),500);
						 }
					}
				}); */
    	 
     		});
     });
	</script>
</html>
